import Vue from 'vue'
console.log('-----------------------------scroll-')

Vue.directive('searchshow', {
  inserted (el) {
    // 插入到dom之后的钩子函数
    var top = 0
    window.onscroll = () => {
      console.log('scroll', el, top)
      var scrollS = (document.documentElement.scrollTop || document.body.scrollTop)
      if (scrollS > top) {
        // 显示
        top = scrollS
        el.style.display = 'none'
      } else {
        // 隐藏
        el.style.display = 'block'
        top = scrollS
      }
    }
  },
  unbind () {
    // 指令的解绑的生命周期 钩子函数
    // window.onscroll = null
  }
})
